package com.hzg.springcloud.controller;

import com.hzg.springcloud.domain.Product;
import com.hzg.springcloud.service.IProductService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ Description: TODO
 * @ Author: 卓哥
 * @ Date: 2020/8/28 11:42
 * @ Version: 1.0
 */
//@RestController
//@RequestMapping("products")
public class ProductController {
    @Autowired
    private IProductService productService;
    @Value("${server.port}")//获取配置文件的端口   主要是看拿到的是哪一个
    private String port;
    @GetMapping("/get/{id}")//使用restFul风格  @PathVariable表明要拿url拼接上面的id值
    private Object get(@PathVariable Long id){
        Product product = productService.get(id);
        //想让order-server服务调用product集群时,知道调用那个服务(8080/8081)
        //product.setName(product.getName()+"\tip=="+port);
        Product pp = new Product();
        BeanUtils.copyProperties(product,pp);
        pp.setName(product.getName() + "_" + port);
        return pp;
    }
}
